import request from '@/utils/request'

// 查询设备列表
export function listEquipment(query) {
  return request({
    url: '/ldzl-sb/sb/equipment/list',
    method: 'get',
    params: query
  })
}

// 查询设备详细
export function getEquipment(equipmentId) {
  return request({
    url: '/ldzl-sb/sb/equipment/' + equipmentId,
    method: 'get'
  })
}

// 新增设备
export function addEquipment(data) {
  return request({
    url: '/ldzl-sb/sb/equipment',
    method: 'post',
    data: data
  })
}

// 修改设备
export function updateEquipment(data) {
  return request({
    url: '/ldzl-sb/sb/equipment',
    method: 'put',
    data: data
  })
}

// 删除设备
export function delEquipment(equipmentId) {
  return request({
    url: '/ldzl-sb/sb/equipment/' + equipmentId,
    method: 'delete'
  })
}

// 导出设备
export function exportEquipment(query) {
  return request({
    url: '/ldzl-sb/sb/equipment/export',
    method: 'post',
    data: query
  })
} 

// 检查设备编码是否已存在
export function checkEquipmentCode(equipmentCode) {
  return request({
    url: '/ldzl-sb/sb/equipment/checkEquipmentCode',
    method: 'get',
    params: { equipmentCode }
  })
}

// 检查设备编码是否存在（排除自身）
export function checkEquipmentCodeExcludeSelf(equipmentCode, equipmentId) {
  return request({
    url: '/ldzl-sb/sb/equipment/checkCodeExcludeSelf',
    method: 'get',
    params: { 
      equipmentCode: equipmentCode,
      equipmentId: equipmentId
    }
  })
}

// 获取自动生成的编码
export function generateCodes(params) {
  return request({
    url: '/ldzl-sb/sb/equipment/generateCodes',
    method: 'get',
    params: params
  })
} 

// 生成设备编码
export function generateEquipmentCode(type) {
  return request({
    url: '/ldzl-sb/sb/equipment/generate/code/' + type,
    method: 'get'
  })
}

// 更新设备状态
export function updateEquipmentStatus(equipmentId, status, reason) {
  const data = {
    equipmentId: equipmentId,
    status: status,
    reason: reason
  }
  return request({
    url: '/ldzl-sb/sb/equipment/status',
    method: 'put',
    data: data
  })
}

// 获取设备状态统计
export function getEquipmentStatusStats() {
  return request({
    url: '/ldzl-sb/sb/equipment/status/stats',
    method: 'get'
  })
} 

// 获取设备点检记录
export function getEquipmentInspectionRecords(equipmentId, query) {
  return request({
    url: `/ldzl-sb/sb/equipment/${equipmentId}/inspection/records`,
    method: 'get',
    params: query
  })
}

// 获取设备保养记录
export function getEquipmentMaintenanceRecords(equipmentId, query) {
  return request({
    url: `/ldzl-sb/sb/equipment/${equipmentId}/maintenance/records`,
    method: 'get',
    params: query
  })
}

// 获取设备维修记录
export function getEquipmentRepairRecords(equipmentId, query) {
  return request({
    url: `/ldzl-sb/sb/equipment/${equipmentId}/repair/records`,
    method: 'get',
    params: query
  })
} 

// 检查设备编码是否存在（新增时）
export function checkEquipmentCodeExists(equipmentCode) {
  return request({
    url: '/ldzl-sb/sb/equipment/checkCode',
    method: 'get',
    params: { equipmentCode }
  })
} 